from rest_framework.decorators import api_view
from django.http import JsonResponse
from django.db import connection


# Create your views here.
@api_view(["get"])
def home(request):
    with connection.cursor() as cursor:
        cursor.execute("select count(id) as student_item from login_student "
                       "union all "
                       "select count(coach_id) as coach_item from login_coach_info "
                       "union all "
                       "select count(car_id) as car_item from login_car_info where car_state = TRUE "
                       "union all "
                       "select count(id) as student_item from login_student where is_graduate=TRUE")
        data = cursor.fetchall()
        print(data)
        student_item = data[0][0]
        coach_item = data[1][0]
        car_item = data[2][0]
        graduate_item = data[3][0]
    return JsonResponse({"code": 200, "student_item": student_item, "coach_item": coach_item, "car_item": car_item,
                         "graduate_item": graduate_item})
